package jjn.round1;

import java.util.Arrays;

/**
 * @author Jiang Jining
 * @since 2022-11-14 23:28
 */
public class LeetCode252_MeetingRooms {
    public boolean canAttendMeetings(int[][] intervals) {
        if (intervals == null || intervals.length <= 1) {
            return true;
        }
        Arrays.sort(intervals, (i1, i2) -> {
            int first = i1[0];
            int second = i2[0];
            return Integer.compare(first, second);
        });
        int lastEnd = intervals[0][1];
        for (int i = 1; i < intervals.length; i++) {
            int next = intervals[i][0];
            if (next < lastEnd) {
                return false;
            }
            lastEnd = intervals[i][1];
        }
        return true;
    }
}
